//LittlePig
#include<bits/stdc++.h>
using namespace std;
int t;
int n,m,l,mv;
int d[11111],v[11111],a[11111];
int cs[11111];
int mcs;
int ans;
void solve()
{
    scanf("%d%d%d%d",&n,&m,&l,&mv);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&d[i],&v[i],&a[i]);
    }
    mcs=0;
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&cs[i]);
        mcs=max(mcs,cs[i]);
    }
    ans=0;
    for(int i=1;i<=n;i++)
    {
        if(v[i]>mv&&d[i]<mcs) ans++;
    }
    printf("%d ",ans);
    if(m>0&&ans)printf("%d\n",m-1);
    else printf("%d\n",m);
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&t);
    for(int i=1;i<=t;i++) solve();
    return 0;
}
